package com.itheima.ticket2;


public class Ticket implements Runnable {
    private int count = 100;
    private Object obj = new Object();

    @Override
    public void run() {
        System.out.println("obj:" + obj);
        //卖票
        while (true) {
            synchronized (this) {
                if (count > 0) {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    String name = Thread.currentThread().getName();
                    count--;
                    System.out.println(name + "卖了一张票,剩余" + count + "张票");
                } else {
                    break;
                }
            }


        }
    }
}
